﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace FYPDemo
{
    public partial class Survey_Report1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            string vendor = "";
            string dateFrom = "";
            string dateTo = "";

            vendor = txtVendor.Text;

            if (txtDateFrom.Text != "")
            {
                dateFrom = txtDateFrom.Text + " 00:00:00.000";
                Session["datefrom"] = txtDateFrom.Text;
            }

            if (txtDateTo.Text != "")
            {
                dateTo = txtDateTo.Text + " 23:59:59.998";
                Session["dateto"] = txtDateTo.Text;
            }

            DataTable dt = BackOffice_Report.Survey_Report1(vendor, dateFrom, dateTo);
            Survey_Report1_Grid.DataSource = dt;
            Survey_Report1_Grid.DataBind();
        }

        protected void Survey_Report1_Grid_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Vendor")
            {
                int index = Convert.ToInt32(e.CommandArgument);
                string vendor = Survey_Report1_Grid.DataKeys[index].Values["Vendor"].ToString(); ;

                Response.Redirect("Survey_Report2.aspx?Vendor=" +vendor);
            }
        }

        protected void btnExport_Click(object sender, EventArgs e)
        {
            DateTime dt = DateTime.Now;

            string year = dt.Year + "";
            string month = dt.Month + "";
            string day = dt.Day + "";
            string fileName = "Survey_Report" + year + month + day;
            GridViewExportUtil.Export(fileName + ".xls", this.Survey_Report1_Grid);
        }
    }
}